﻿@model DDLViewModel

@{
    List<Property> properties = ViewBag.Properties;
}

@if (properties.Count > 0)
{
    PropertyType propertyType = ViewBag.PropertyType;
    string propertyNameId = ViewBag.PropertyNameId;

    string name = propertyType.NameVn ?? propertyType.Name;
    string nameId = propertyType.Name.Replace(" ", "");

    <div class="form-group">
        <span class="title">@name:</span>

        @if (properties.Count == 1)
        {
            Property property = properties.First();
            
            <span class="value">@property.Name</span>
            @Html.Hidden(nameId, property.NameId)
        }
        else
        {
            @Html.DropDownList(nameId, new SelectList(properties, "NameId", "Name", propertyNameId),
            String.Format("Chọn {0}", name.ToLower()),
            new { @class = "form-control", onchange = "this.form.submit();" })

            @Html.ValidationMessage(nameId, String.Format("Vui lòng chọn {0}.", name.ToLower()))
        }
    </div>
}

